/**
 * tandelin  2017-07-06
 */
//点击展示所有热评新闻
var param = {
        lastTime: '2017-08-30',
        offset:1,
        limit:50,
        pageSize:100
    };

function ajax(url, param) {
    return $.ajax({
        url: url,
        data: param || {},
        type: 'POST',
        dataType: "json",
        beforeSend: function (request) {
            request.setRequestHeader("Authorization", localStorage.token)
        }
    });
};

/*
 * 获取新闻列表信息
 */
ajax("../news/posts/getHotCommentNews",param).done(function (resp){
    var data = resp;
    for(var i = 0;i<data.data.length;i++){
        var newsType = JSON.parse(data.data[i].listLayout),
            newsTime = new Date(data.data[i].showDate),
            newsDay = [newsTime.getFullYear(),newsTime.getMonth()+1,newsTime.getDate(),newsTime.getHours()<10?'0'+ newsTime.getHours():newsTime.getHours(),newsTime.getMinutes()<10?'0'+ newsTime.getMinutes():newsTime.getMinutes(),newsTime.getSeconds()<10?'0'+ newsTime.getSeconds():newsTime.getSeconds()],
            newsShowTime = newsDay[0]+"-"+newsDay[1]+"-"+newsDay[2]+" "+newsDay[3]+":"+newsDay[4]+":"+newsDay[5];
        if(data.data[i].listLayout == null){
            continue;
        };
        if(newsType.layout_type == '0'){
            var template = $('#newsTemplateFive').clone().html(),
                html = template.replace('这处旅游胜地拒绝对歪果仁开放，只接收大天朝的游客观光',data.data[i].postTitle);
            //html = html.replace('某某网',data.data[i].authors.name);
            html = html.replace('2016-05-24',newsShowTime);
            html = html.replace('http://www.----.com',data.data[i].newsUrl);
            $('#newsListUl').append(html);
        }else if(newsType.layout_type == '1'){
            var template = $('#newsTemplateFour').clone().html(),
                html = template.replace('下半年中国将会发生哪些大事，与我们...',data.data[i].postTitle);
            //html = html.replace('某某网',data.data[i].authors.name);
            html = html.replace('2016-05-24',newsShowTime);
            //html = html.replace('http://www.----.com',data.data[i].newsUrl);
            html = html.replace('image/xinwenthree.jpg',newsType.layout_imgs[0]);
            html = html.replace('image/aobama.jpg',newsType.layout_imgs[1]);
            html = html.replace('image/gangaowan.jpg',newsType.layout_imgs[2]);
            $('#newsListUl').append(html);
        }else if(newsType.layout_type == '2'){
            var template = $('#newsTemplateOne').clone().html(),
                html = template.replace('这处旅游胜地拒绝对歪果仁开放，只接收大天朝的游客观光',data.data[i].postTitle);
            //html = html.replace('某某网',data.data[i].authors.name);
            html = html.replace('2016-05-24',newsShowTime);
            html = html.replace('image/aobama.jpg',newsType.layout_imgs[0]);
            //html = html.replace('http://www.----.com',data.data[i].newsUrl);
            $('#newsListUl').append(html);
        }else if(newsType.layout_type == '3'){
            var template = $('#newsTemplateTwo').clone().html(),
                html = template.replace('回顾奥巴马在任期间对IS的武装措施',data.data[i].postTitle);
            //html = html.replace('某某网',data.data[i].authors.name);
            html = html.replace('2016-05-24',newsShowTime);
            html = html.replace('image/aobama.jpg',newsType.layout_imgs[0]);
            //html = html.replace('http://www.----.com',data.data[i].newsUrl);
            $('#newsListUl').append(html);
        }else if(newsType.layout_type == '4'){
            var template = $('#newsTemplateThree').clone().html(),
                html = template.replace('昨日凌晨，印度尼西亚发生1.0级地震，市民声称震感强烈',data.data[i].postTitle);
            html = html.replace('某某网',data.data[i].authors.name);
            html = html.replace('2016-05-24',newsShowTime);
            html = html.replace('image/aobama.jpg',newsType.layout_imgs[0]);
            //html = html.replace('http://www.----.com',data.data[i].newsUrl);
            $('#newsListUl').append(html);
        }else if(newsType.layout_type == '5'){
            var template = $('#newsTemplateSix').clone().html(),
                html = template.replace('这处旅游胜地拒绝对歪果仁开放，只接收大天朝的游客观光',data.data[i].postTitle);
            //html = html.replace('某某网',data.data[i].authors.name);
            html = html.replace('2016-05-24',newsShowTime);
            html = html.replace('image/gangaowan.jpg',newsType.layout_imgs[0]);
            //html = html.replace('http://www.----.com',data.data[i].newsUrl);
            $('#newsListUl').append(html);
        }else{
            var template = $('#newsTemplateSeven').clone().html(),
                html = template.replace('下半年中国将会发生哪些大事，与我们...',data.data[i].postTitle);
            //html = html.replace('某某网',data.data[i].authors.name);
            html = html.replace('2016-05-24',newsShowTime);
            //html = html.replace('http://www.----.com',data.data[i].newsUrl);
            html = html.replace('image/xinwenthree.jpg',newsType.layout_imgs[0]);
            html = html.replace('image/aobama.jpg',newsType.layout_imgs[1]);
            html = html.replace('image/gangaowan.jpg',newsType.layout_imgs[2]);
            $('#newsListUl').append(html);
        };
    };
});